// pages/order/input/input.js
import {
  OrderModel
} from '../../../model/order'
var order = new OrderModel()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showActionsheet: false,
    groups: [{
        text: '美芙坊五大道会所',
        value: "美芙坊五大道会所"
      },
      {
        text: '美芙坊罗马会所 ',
        value: "美芙坊罗马会所"
      },
      {
        text: '美芙坊万达会所 ',
        value: "美芙坊万达会所"
      },
      {
        text: '美芙坊奥城会所 ',
        value: "美芙坊奥城会所"
      },
      {
        text: '美芙坊财富会所 ',
        value: "美芙坊财富会所"
      },
    ],
    showActionsheet1: false,
    groups1: [],
    realName: '',
    phone: '',
    address: '',
    store: '',
    type: '',
    typeId: ''
  },
  close: function () {
    this.setData({
      showActionsheet: false,
      showActionsheet1: false
    })
  },
  btnClick(e) {
    console.log(e)
    this.setData({
      store: e.detail.value
    })
    this.store = e.detail.value
    this.close()
  },
  btnClick1(e) {
    console.log(e)
    this.setData({
      type: this.data.groups1[e.detail.index].text,
      typeId: e.detail.value
    })
    this.close()
  },
  chooseStore() {
    this.setData({
      showActionsheet: true
    })
  },
  onNameChange(e) {
    this.data.realName = e.detail.value
  },
  onMobileChange(e) {
    this.data.phone = e.detail.value
  },
  chooseAction() {
    let _this = this;
    wx.authorize({
      scope: 'scope.userLocation',
      success() {
        wx.chooseLocation({
          success: res => {
            _this.setData({
              address: res.address
            })
          }
        })
      },
      fail() {}
    })
  },
  chooseType() {
    this.setData({
      showActionsheet1: true
    })
  },
  submit() {
    order.orderEntry(this.data.realName, this.data.phone, this.data.address, this.data.store, this.data.typeId).then(res => {
      if (res.code == 0) {
        wx.navigateBack({
          complete: () => {
            wx.showToast({
              title: '保存成功',
            })
          }
        })
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'none'
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    order.customMadeGoodsList().then(res => {
      if (res.code == 0) {
        var groups1 = [];
        for (var i = 0; i < res.data.records.length; i++) {
          groups1[i] = {
            text: res.data.records[i].styleName,
            value: res.data.records[i].id
          }
        }
        that.setData({
          groups1: groups1
        })
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'none'
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})